define(function(require, exports, module) {
    var router = require("router");
    //var app = require("app");
    var controller = {};
    controller.vue = function() {
        controller.vm = new Vue({
            router: router,
            data: function() {
                return {
                    shop_info: {},
                    store:{},
                    loading:0,
                    cardQrcodeInfo:{},
                    downUrl:''
                    
                };
            },
            el: '#pageShopQCode',
            created: function() {
                this.fetchData();
            },
             mounted: function() {
                if (this.mounted == 1) {
                    return;
                }
                this.mounted = 1;
                app.copy("#shareClipboard",function(res){
                   console.log(res);
                   if(res=="success"){
                     app.alert("链接复制成功");
                   }else{
                     this.share();
                   }
                });
            },

            methods: {
                fetchData: function() {
                    var _this = this;

                    this.getInfo();
                    this.getCardQrcode();
                   
                },
                getCardQrcode:function(){
                  //如果是微信打开卡包
                   var user_info =  app.getUserInfo();
                    
                   this.url = app.params.apiDomain+'/mall/pages/renderPage?shop_id='+this.$route.params.shop_id +'&page=pages%2Findex%2Findex';
                   this.show_qrcode_url= app.params.apiDomain+"/api/index/urlQRcode?url="+encodeURIComponent(this.url);
                   
                },
                
                 share:function(){
                  var text = '复制链接发给朋友：'+this.url ;
                  if(app.isWeiXin()){
                    text = "请点击微信右上角分享给好友";
                  }
                  app.confirm({
                    text:text
                  });
                },
                
                getInfo:function(){
                    var that = this;
                    if( that.loading == 1){
                        return ;
                     }
                     that.loading = 1;
                    
                    var user_info =  app.getUserInfo();
                    
                    app.get("mall/shop/find", {
                      id : this.$route.params.shop_id 
                     
                    }, function (res) {
                      that.loading = 0;
                      if (res.code != 200) {
                         app.alert(res.msg);
                         return ;
                      }
                      
                      that.shop_info = res.data;
                      
                      
                    });
                }
            }

        }).$mount('#app');
    };
    module.exports = controller;
});
